import { ApiProperty } from '@nestjs/swagger';
import { IsString, IsNumber, IsOptional, IsBoolean, Min, Length, IsEnum } from 'class-validator';

export enum MenuType {
  MENU = 1,    // 菜单
  DIRECTORY = 2, // 目录
  EXTERNAL = 3,  // 外链
  BUTTON = 4     // 按钮
}

export class CreateMenuDto {
  @ApiProperty({
    description: '父菜单ID',
    default: 0
  })
  parent_id: number;

  @ApiProperty({
    description: '菜单路径',
    required: false,
  })
  tree_path?: string;

  @ApiProperty({
    description: '菜单名称',
    example: '系统管理'
  })
  @IsString()
  @Length(2, 50, { message: '菜单名称长度必须在2-50个字符之间' })
  name: string;

  @ApiProperty({
    description: '菜单类型(1-菜单 2-目录 3-外链 4-按钮)',
    enum: MenuType,
  })
  @IsEnum(MenuType, { message: '无效的菜单类型' })
  type: MenuType;

  @ApiProperty({
    description: '路由名称',
    required: false,
  })
  @IsOptional()
  @IsString()
  @Length(2, 50)
  route_name?: string;

  @ApiProperty({
    description: '路由路径',
    required: false,
  })
  @IsOptional()
  @IsString()
  @Length(1, 100)
  route_path?: string;

  @ApiProperty({
    description: '组件路径',
    required: false,
    example: '@/views/system/index'
  })
  @IsOptional()
  @IsString()
  @Length(1, 100)
  component?: string;

  @ApiProperty({
    description: '权限标识',
    required: false,
    example: 'system:view'
  })
  @IsOptional()
  @IsString()
  @Length(1, 100)
  perm?: string;

  @ApiProperty({
    description: '显示顺序',
    required: false,
    default: 0,
    minimum: 0,
    maximum: 999
  })
  @IsOptional()
  @IsNumber()
  @Min(0)
  sort?: number;

  @ApiProperty({
    description: '菜单图标',
    required: false,
    example: 'setting'
  })
  @IsOptional()
  @IsString()
  icon?: string;

  @ApiProperty({
    description: '是否显示',
    required: false,
    default: true
  })
  @IsOptional()
  @IsBoolean()
  visible?: boolean;

  @ApiProperty({
    description: '重定向地址',
    required: false,
    example: '/system/user'
  })
  @IsOptional()
  @IsString()
  @Length(1, 100)
  redirect?: string;

  @ApiProperty({
    description: '是否始终显示',
    required: false,
    default: 0
  })
  @IsOptional()
  @IsNumber()
  @Min(0)
  always_show?: number;

  @ApiProperty({
    description: '是否开启页面缓存',
    required: false,
    default: 0
  })
  @IsOptional()
  @IsNumber()
  @Min(0)
  keep_alive?: number;
}